<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- React 底层核心库 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.development.js"></script>
    <!-- React 操作 Dom 库，类似 JQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.development.min.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="root"></div>
    <script type="text/babel">

        class ForComponent extends React.Component {
            constructor() {
                super();
            }

            state = {
                list: ['张三', '李四', '王五', '赵六']
            }

            render() {
                return <div>
                    <ul>
                        {
                            this.state.list.map(item => <li key={item}>{item} </li>)
                        }
                    </ul>
                </div>
            }
        }

        function Login() {
            return <div>
                登录成功
            </div>
        }

        function NotLogin() {
            return <div>
                尚未登录
            </div>
        }

        class IFComponent extends React.Component {
            constructor() {
                super()
            }

            state = {
                isLogin: true
            }

            handleClick = () => {
                this.setState({
                    isLogin: !this.state.isLogin
                })
            }

            render() {
                return <div>
                    <button onClick={this.handleClick}>
                        {this.state.isLogin ? '退出' : '登录'}
                    </button>
                    {
                        this.state.isLogin ? <Login /> : <NotLogin />
                    }
                </div>
            }
        }

        class App extends React.Component {
            constructor(props) {
                super(props);
                // this.handleClick = this.handleClick.bind(this);
            }
            render() {
                return <div>
                    <h2> 循环遍历 </h2>
                    <ForComponent />

                    <h2> 条件渲染 </h2>
                    <IFComponent />
                </div>
            }
        }

        ReactDOM.createRoot(document.querySelector('#root')).render(<App />)
    </script>
</body>

</html>